package java虚拟机.chapter7;

/**
 * @author juntao zhang
 */
public class DeadLoopClass {

  static class Test {

    static {
      if (true) {
        System.out.println(Thread.currentThread() + " init DeadLoopClass");//only once
        while (!Thread.currentThread().isInterrupted()) {
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
          }
        }
      }
    }
  }

  public static void main(String[] args) {
    Runnable script = new Runnable() {
      @Override
      public void run() {
        System.out.println(Thread.currentThread() + " start");
        Test test = new Test();
        System.out.println(Thread.currentThread() + " end");
      }
    };
    Thread thread1 = new Thread(script, "1");
    Thread thread2 = new Thread(script, "2");
    thread1.start();
    thread2.start();
    thread1.interrupt();
//    thread2.interrupt();
  }

}
